﻿using Bot.Dynamics365.Model;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace Bot.Dynamics365.Extension
{
    public static class HttpClientFactoryExtensions
    {
        public static async Task<HttpResponse> SendAsync(this IHttpClientFactory httpClientFactory, HttpRequestMessage request)
        {
            var client = httpClientFactory.CreateClient();
            var httpResponseMessage = await client.SendAsync(request);
            var response = await httpResponseMessage.Content.ReadAsStringAsync();
            return new HttpResponse()
            {
                IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode,
                StatusCode = httpResponseMessage.StatusCode,
                Response = response,
            };
        }
    }
}
